package com.gm.wholesale.module.order.presenter;
import android.util.ArrayMap;
import com.gm.commonlib.base.baseBean.BaseListResp;
import com.gm.commonlib.base.baseView.IBaseView;
import com.gm.commonlib.network.BaseHttpObserver;
import com.gm.wholesale.module.good.bean.GoodBean;
import com.gm.wholesale.module.good.model.GoodModel;
import java.util.List;

public class MainOrderFgPresenter {
    public interface OnSearchGoodFinishListener{
        void onSearchGood(List<GoodBean> goodBeans);
    }

    //更具名字模糊查找
    public static void searchGoodByKey(IBaseView iBaseView,String goodName,OnSearchGoodFinishListener listener){
        ArrayMap<String,Object> queryData=new ArrayMap<>();
        queryData.put("keyword",goodName);
        GoodModel.getSearchGood(iBaseView, queryData, new BaseHttpObserver<>() {
            @Override
            protected void handleResultOkResp(BaseListResp<GoodBean> resp) {
                listener.onSearchGood(resp.getDatas());
            }

            @Override
            protected void handleResultOtherResp(BaseListResp<GoodBean> resp) {
                listener.onSearchGood(null);
            }

            @Override
            protected void onError(String error) {
                listener.onSearchGood(null);
            }
        });
    }

    //根据名字和单位精确查找
    public static void searchGoodByName(IBaseView iBaseView,ArrayMap<String,Object> data,OnSearchGoodFinishListener listener){

        GoodModel.getSearchGood(iBaseView, data, new BaseHttpObserver<>() {
            @Override
            protected void handleResultOkResp(BaseListResp<GoodBean> resp) {
                listener.onSearchGood(resp.getDatas());
            }

            @Override
            protected void handleResultOtherResp(BaseListResp<GoodBean> resp) {
                listener.onSearchGood(null);
            }

            @Override
            protected void onError(String error) {
                super.onError(error);
                listener.onSearchGood(null);
            }
        });
    }
}
